package com.jiang.vo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.DelayQueue;

public class Teacher implements Runnable {

	private DelayQueue<Student> queue;
	private int studentNum; // 学生人数
	private int subNum = 0; // 交卷人数

	public Teacher(DelayQueue<Student> queue, int studentNum) {
		this.queue = queue;
		this.studentNum = studentNum;
	}

	@Override
	public void run() {
		System.out.println("考试开始:" + new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
		// 如果交卷的人数不到总人数
		while (this.subNum < this.studentNum) {
			try {
				Student stu = queue.take();
				if (stu != null) {
					System.out.println(stu);
					subNum++;
				}

			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println("所有的同学都已经交卷!!!");
	}

}
